﻿using PremisPublisher.ViewModel;
using GalaSoft.MvvmLight.Messaging;
using ICSharpCode.AvalonEdit.CodeCompletion;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using PremisPublisher.Messages;

namespace PremisPublisher
{
    /// <summary>
    /// Interaction logic for SQLContentEditorWindow.xaml
    /// </summary>
    public partial class SQLContentEditorWindow : Window
    {
        public SQLContentEditor model;

        public SQLContentEditorWindow()
        {
            InitializeComponent();
            model = this.DataContext as SQLContentEditor;

            Loaded += SQLContentEditorWindow_Loaded;

            Messenger.Default.Register<UploadResultMessage>(this, msg =>
            {

                MessageBox.Show(string.Format("{0} 代码：{1}", msg.Message, msg.Code));
            });

            Closed += SQLContentEditorWindow_Closed;
        }

        void SQLContentEditorWindow_Closed(object sender, EventArgs e)
        {
            Messenger.Default.Unregister<UploadResultMessage>(this);
        }

        void SQLContentEditorWindow_Loaded(object sender, RoutedEventArgs e)
        {
            using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("PremisPublisher.sql_syntax.xml"))
            {
                using (var reader = new System.Xml.XmlTextReader(stream))
                {
                    this.ava_editor.SyntaxHighlighting =
                ICSharpCode.AvalonEdit.Highlighting.Xshd.HighlightingLoader.Load(reader,
                ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance);
                }
            }
        }
    }
}
